<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
	body,html{
		margin: 0 auto;
		height:100%;
		width:100%;
		overflow:hidden;
	}
</style>
</head>
<body>
		<div id="Commodity_add_commodityType" style="width:100%;height:100%;" class="divfrist">
			<DIV id="" style="width:100%;height:0.7%;overflow:hidden;"></DIV>
			<DIV id="" style="width:100%;height:98.6%;">
					<DIV id="" class="" style="float:left;width:0.4%;height:100%;overflow:hidden;"></DIV>
					<DIV id="" class="" style="float:left;width:49.4%;height:100%;">
							<DIV id="" class="allborder" style="width:100%;height:100%;max-height:100%;max-width:100%;">
								<!-- 内容区 -->
											<div class="easyui-panel" title="商品类型树" style="width:100%;" data-options="fit:true,border:false">
												<div style="padding:10px 0 10px 10px">
											    	<ul id="commodityTypeTree" class="ztree" style="margin-top:0; width:160px;"></ul>
											    </div>
											</div> 
								<!-- 内容区 -->
							</DIV>
					</DIV>
					<DIV id="" class="" style="float:left;width:0.4%;height:100%;overflow:hidden;"></DIV>
					<DIV id="" class="" style="float:left;width:49.4%;height:100%;">
							<DIV id="" class="allborder" style="width:100%;height:100%;max-height:100%;max-width:100%;margin-left: -1px;">
								<!-- 内容区 -->
											<div class="easyui-panel" title="商品类型基本信息" style="width:100%;" data-options="fit:true,border:false">
												<div style="padding:10px 0 10px 60px">
											    <form id="Commodity_add_commodityType_from" method="post">
											    	<table>
											    	
											    		<tr>
											    			<td>主键ID:</td>
											    			<td><input class="easyui-validatebox" type="text" name="comTypeId"  id="comTypeId"></input></td>
											    		</tr>
											    		<tr>
											    			<td>上级类型ID:</td>
											    			<td><input class="easyui-validatebox" type="text" name="pId"  id="pId"></input></td>
											    		</tr>
											    		<tr>
											    			<td>上级类型:</td>
											    			<td><input class="easyui-validatebox" type="text" name="pname" id="pname" disabled="disabled"></input></td>
											    		</tr>
											    		<tr>
											    			<td>类型名称:</td>
											    			<td><input class="easyui-validatebox" type="text" name="name"  id="name"></input></td>
											    		</tr>
											    	</table>
											    </form>
											    </div>
											    <div style="text-align:center;padding:5px">
											    	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="window.CommodtityType.addcommodityType()">增加</a>
											    	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="clearForm()">清空</a>
											    </div>
											</div>
							<!-- 内容区 -->
							</DIV>
					</DIV>
					<DIV id="" class="" style="float:left;width:0.37%;height:100%;overflow:hidden;"></DIV>
			</DIV>
			<DIV id="" class="div_bottom"></DIV>
	</div>
		
</body>
<script>
(function(){
		
		//设定所有文本验证方法
		function validateInput(){
			var valuetype=["length[3,15]","unnormal"];
			  
			$('#name').validatebox({   
			    required: true,   
			    validType:  ["unnormal","length[3,15]"]  
			}); 
		 
			
		}
		//增加类型
		function addcommodityType(){
			var zTree = $.fn.zTree.getZTreeObj("commodityTypeTree");
			nodes = zTree.getSelectedNodes();
			if(nodes&&nodes.length>0){
				if($("#pId")==$("#id").val()){
					alert("不能设置自己为自己的上级类型!请选择其他类型");
					return;
				}
			}
			$.messager.progress({
				title:'请注意',
				text:'数据正在加载.....'
			});
			$('#Commodity_add_commodityType_from').form('submit', {
					url: "${pageContext.request.contextPath}/jxc/commodtityTypeAction!addCommodtityType.action",
					onSubmit: function(){
					var isValid = $(this).form('validate');
					if (!isValid){
						$.messager.progress('close');	// 当form不合法的时候隐藏工具条
					}
					return isValid;	// 返回false将停止form提交 
				},
				success: function(data){
					$.messager.progress('close');
					if(data=="success"){
						alert("增加类型成功");
						createUpdateTree();
					}else if(data=="same"){
						alert("已经有相同名称的类型存在");
					}else if(data=="us"){
						alert("更新成功");
					}else{
						alert("操作失败");
					}
					// 当成功提交之后隐藏进度条
				}
			});
		}
		//双击树改变类型选择
		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("commodityTypeTree");
			nodes = zTree.getSelectedNodes();
			$("#pname").val(nodes[0].name);
			$("#pId").val(nodes[0].id);
			//$("#comTypeId").val(nodes[0].comTypeId);
			
		}
		//创建树
		function createUpdateTree(){
			
			var setting = {
					view: {
						dblClickExpand: false
					},
					data: {
						simpleData: {
							enable: true
						}
					},
					callback: {
						onClick: onClick
					}
				};
			$.ajax({
				   type: "POST",
				   url: "${pageContext.request.contextPath}/jxc/commodtityTypeAction!getCommodtityTypeTree.action",
				   data:{areaId:"${areaId}"},
				   dataType:'json',
				   success: function(msg){
					   try{
						   var node = new Object();
						   node.uuid=0;
						   node.id=1;
						   node.pid=0;
						   node.name="所有类型";
						   node.open=true;
						   msg.push(node);
						   $.fn.zTree.init($("#commodityTypeTree"), setting, msg);  	   
						   
					   }catch(e){
						   alert(e);
					   }
					 
				   }
			});	
		}
		
		
		$(function(){
				$.parser.parse('#Commodity_add_commodityType'); 
				validateInput();
				createUpdateTree();
		});
		window.CommodtityType={};
		window.CommodtityType.addcommodityType=addcommodityType;
	 
		
		
	})();
	
	</script>
</html>